﻿///////////////////////////////////////////////////////////////////////////////
// File:        EpollReactor.hpp
// Author:      671643387@qq.com
// Description:
///////////////////////////////////////////////////////////////////////////////

#ifndef NIO_NET_DETAIL_EPOLLREACTOR_HPP_
#define NIO_NET_DETAIL_EPOLLREACTOR_HPP_

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif

#include <boost/unordered_map.hpp>
#include <sys/epoll.h>
#include <nio/net/Reactor.hpp>

namespace nio
{
    namespace net
    {
        namespace detail
        {
            class EpollReactor : public Reactor
            {
            public:
                EpollReactor(void);
                virtual ~EpollReactor(void);

                virtual bool addSource(sock_t sock, Event events, EventHandler* handler);
                virtual void removeSource(sock_t sock);
                virtual void doTick(base::time_t timeout = 0);
                virtual void setMode(Mode mode) { mode_ = mode; }

            private:
                typedef boost::unordered_map<sock_t, EventHandler*> SourceMap;

            private:
                int                     epfd_;
                Mode                    mode_;
                nio::base::time_t       lastHeartbeatTime_;
                SourceMap               sources_;
            };
        }
    }
}

#endif //NIO_NET_DETAIL_EPOLLREACTOR_HPP_
